/**
 * 张志浩(作者)
 * 2018-05-17(开始日期)
 * 2018--(最终更改日期)
 * xxx(最后更改者)
 * */
//var apicom = "http://192.168.30.199:10001/";
var v = globalFun.GetQueryString("v");
var oId = globalFun.GetQueryString("oId");
//v = "24"
/* 时间戳转日期时间 */
function stamp2time(timestamp, showhour) {
  var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
  Y = date.getFullYear() + '-';
  M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + ' ';
  h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours() + ':';
  m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  //s = date.getSeconds();
  if (showhour) {
    var str = Y + M + D + " " + h + m;
  } else {
    var str = Y + M + D;
  }
  return str;
}

function getServiceInfo() {
  Auth();
  $.ajax({
    url: apicom + "mobile/after/order/queryServiceOrderDetail",
    type: "post",
    data: {
      orderNo: v,
      uuid: user_info.uuid,
      phone: user_info.phone
    },
    success: function(res) {
      if (typeof(res) == 'string') {
        res = JSON.parse(res);
      }
      var data = res.content;
      if (res.code == 1) {
        var stime = "",
          etime = "";
        if (data.serviceOrder.endTime) {
          stime = stamp2time(data.serviceOrder.beginTime);
          etime = "至" + stamp2time(data.serviceOrder.endTime);

        } else {
          stime = stamp2time(data.serviceOrder.beginTime, true);
        }
        $("#service_name").html(data.projectMap.title)
        $("#service_time").html(stime + etime)
        $("#service_code").html(data.serviceOrder.code)
        //生成二维码
        var qrcode = new QRCode(document.getElementById("QRCode_img"), {
          width: $("#QRCode_img").width(), //设置宽高
          height: $("#QRCode_img").height()
        });
        qrcode.makeCode("0&" + oId + "&" + data.serviceOrder.code);
      }
    }
  })
}
getServiceInfo();
/* 查看订单详情 */
$("#to_detail").click(function() {
  if ($(self).hasClass("disabled")) {
    return false
  }
  $(self).addClass("disabled")
  setTimeout(function() {
    $(self).removeClass("disabled")
  }, 1000)
  if (mark == 1) { //跳转ios
    setupWebViewJavascriptBridge(function(bridge) {
      bridge.callHandler('jsToClientSoDetail', {
        orderNo: oId
      }, function(resp) {});
    });
  } else if (mark == 0) { //跳转android

    window.stub.jsToClientSoDetail(oId); //用接口stub, 通过调用内部类中的方法jsMethod给javas传回result。

  } else {
    downloadApp()
  }
})
/* 浏览器内打开提示下载App */
function downloadApp() {
  var ua = navigator.userAgent.toLowerCase();
  if (/android/.test(ua)) {
    //安卓手机
    location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.yst.onecity&channel=0002160650432d595942&fromcase=60001"
  } else if (/iphone/.test(ua)) {
    //苹果手机
    location.href = "https://itunes.apple.com/us/app/%E6%99%AE%E6%B5%8E%E4%B8%80%E5%9F%8E/id1352933890?l=zh&ls=1&mt=8"
  }
}
/* 完成 */
$(".complete").click(function() {
  var fwMsg = sessionStorage.getItem("fwMsg");
  fwMsg = JSON.parse(fwMsg)
  //window.history.go(-1);
  TiaoZhuan()
  //location.href = rootdomain + "html/homektxq/home_fwxq.html?id=" + fwMsg.fwId
})

function TiaoZhuan() {
  var ua = navigator.userAgent.toLowerCase();
  if (/pjyc_i/.test(ua)) {
    setupWebViewJavascriptBridge(function(bridge) {
      bridge.callHandler('jsToserverorder', function(resp) {});
    });
  } else if (/pujiyicheng/.test(ua)) {
    //var result = lase;
    window.stub.jsToserverorder(); //用接口stub, 通过调用内部类中的方法jsMethod给java传回result。

  }
}
$.init();